<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function getDeviceType() {
            const ua = navigator.userAgent.toLowerCase();
            // 检测是否为微信浏览器
            const isWeChat = /micromessenger/i.test(ua);
            // 检测是否为移动设备
            const isMobile = /mobile|android|iphone|ipod|blackberry|iemobile|opera mini/i.test(ua);
            // 检测是否为平板设备
            const isPad = /tablet|ipad/i.test(ua) && !isMobile;
            // 检测是否为PC端或桌面设备
            const isPc = !isMobile && !isPad;
            // 检测是否为Android设备
            const isAndroid = /android/i.test(ua);
            // 检测是否为iOS设备
            const isiOS = /iphone|ipad|ipod|ios/i.test(ua);
            let deviceType = 'Unknown';
            if (isPc) {
                deviceType = 'Pc';
            } else if (isPad) {
                deviceType = 'Pad';
            } else if (isMobile) {
                deviceType = 'Mobile';
            }
            // 细分移动设备或平板设备类型
            if (deviceType === 'Mobile' || deviceType === 'Pad') {
                if (isWeChat) {
                    deviceType += 'WeChat';
                } else if (isAndroid) {
                    deviceType += 'Android';
                } else if (isiOS) {
                    deviceType += 'Ios';
                }
            }
            return deviceType;
        }
        const deviceType = getDeviceType();
        console.log(deviceType); // 输出：Pc、Pad、Mobile、MobileWeChat、MobileAndroid 或 MobileIos
    </script>
</body>

</html>